#include <string.h>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;

template <class T>
T add(T t1, T t2)
{
    return t1 + t2;
}

//特化模板
//针对通用模板无法处理的一些特殊的参数类型去定义特别的处理方式
template <>
const char * add<const char *>(const char * pstr1,const char * pstr2)
{
    char * p = new char[strlen(pstr1) + strlen(pstr2) + 1]();
    strcpy(p,pstr1);
    strcat(p,pstr2);
    return p;
}

void test0(){
    int a = 1, b = 2;
    cout << add(a,b) << endl;

    const char * p1 = "hello,";
    const char * p2 = "world";
    /* cout << add<string>(p1,p2) << endl; */

    const char * p = add<const char *>(p1,p2);
    cout << p << endl;
    delete [] p;
}

int main(void){
    test0();
    return 0;
}
